/* 
 * File:   Text.cpp
 * Author: agu
 * 
 * Created on 28 de mayo de 2014, 16:09
 */


#include "client_Text.h"
#include "client_InitializationException.h"

Text::Text(const string path, Color color,int size) {
    this->color = color;
    this->size = size;
    this->message="";
    this->font = TTF_OpenFont(path.c_str(), this->size);
    //If there was an error in loading the font
    if (this->font == NULL) {
        throw InitializationException(TTF_GetError());
    }    
}

Text::Text(const Text& orig) {
    this->font = orig.font;
    this->message = orig.message;
    this->size = orig.size;
    this->color = orig.color;
}

Text::~Text() {
    //Close the font
    TTF_CloseFont(font);
}

void Text::setMessage(const string message) {
    this->cleanMessage();
    this->message = message;
}

string Text::getMessage(const string message) {
    return this->message;
}

void Text::cleanMessage() {
    if (!this->message.empty())
        this->message = "";
}
void Text::copy(Surface& surface){
    SDL_Surface* temp= TTF_RenderText_Solid(this->font,this->message.c_str(),this->color.getColorSDL());
    surface.load(temp);
    //SDL_FreeSurface(temp);
}